import {mainNetWork} from './env'
import { ethers, providers, utils } from 'ethers'
export async function IdentificationContract () {
  const main = async () => {
    // 1.创建 provider
    const provider = new ethers.providers.JsonRpcProvider(mainNetWork)
    // 合约abi
    const abiERC721 = [
      "function name() view returns (string)",
      "function symbol() view returns (string)",
      "function supportsInterface(bytes4) public view returns(bool)",
    ];
    // ERC721的合约地址，这里用的BAYC
    const addressBAYC = "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d"
    // 创建ERC721合约实例
    const contractERC721 = new ethers.Contract(addressBAYC, abiERC721, provider)
    // 读取合约的一些信息
    const contractName =  await contractERC721.name() 
    const contractSymbol = await contractERC721.symbol()
    console.log(`合约的名称`, contractName)
    console.log(`合约的代号`, contractSymbol)
    // 2. 利用ERC165的supportsInterface，确定合约是否为ERC721标准
    // ERC721接口的ERC165 identifier
    const selectorERC721 = "0x80ac58cd"
    const isERC721  = await contractERC721.supportsInterface(selectorERC721)
    console.log('合约是否为ERC721标准', isERC721)
  }
  main()
}